package com.kafka.kafkatest.handler;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.ProducerListener;
import org.springframework.kafka.support.SendResult;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFutureCallback;

/**
 * kafka消息投送结果回调
 */
@Component
@Slf4j
public class KafkaSendResultHandler implements ListenableFutureCallback<SendResult<String, Object>> {



    @Override
    public void onFailure(Throwable ex) {
        log.error("kafka消息投送失败=========error:{}",ex.getMessage());
    }

    @Override
    public void onSuccess(SendResult<String, Object> result) {
        log.info("kafka消息投送成功=========key:{},data{}",result.getProducerRecord().key(),result.getProducerRecord().value());
    }
}
